package kgc.qy.controller;

import kgc.qy.pojo.SysRoles;
import kgc.qy.pojo.SysUsers;
import kgc.qy.service.ISysUsersService;
import kgc.qy.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sysuser")
@CrossOrigin
public class SysUserController {

    @Autowired
    private ISysUsersService sysUsersService;

    //模糊查询sysUser列表
    @PostMapping(value = "select")
    private CommonResult selectUserByPram(@RequestParam(value = "account", required = false, defaultValue = "") String account,
                                          @RequestParam(value = "userName", required = false, defaultValue = "") String userName,
                                          @RequestParam(value = "userType", required = false, defaultValue = "") String userType) {
        System.out.println(userType);
        List<SysUsers> sysList = sysUsersService.selectSysUserByPram(account, userName, userType);
        System.out.println(sysList);
        return new CommonResult(200, "查询成功", sysList);
    }

    //获取userType的方法
    @PostMapping(value = "userType")
    private CommonResult selectUserType() {
        List<SysRoles> sysRoles = sysUsersService.selectAllRoles();
        return new CommonResult(200, "用户类型", sysRoles);

    }

    //更改用户账号状态的方法
    @PostMapping(value = "status")
    private CommonResult<String> updateUserStatus(String id, String flag) {
        System.out.println(id+"\t"+flag);
        String f = sysUsersService.updateUserStatusById(id, flag);
        return new CommonResult<>(200,"修改成功",f);
    }
}
